<template>
  <el-card class="content small-padding-card">
    <text-tree
      :tree="treeData"
      :default-expanded-keys="defaultExpandKeys"
    ></text-tree>
  </el-card>
</template>
<script>
import Axios from "axios";
import TextTree from "~/components/TextTree";
import SurfaceDisplacement from "~/views/monitor-control/statistical-analysis/SurfaceDisplacement";
import SaturationLine from "~/views/monitor-control/statistical-analysis/SaturationLine";
import WaterLevel from "~/views/monitor-control/statistical-analysis/WaterLevel";
import InteriorDisplacement from "~/views/monitor-control/statistical-analysis/InteriorDisplacement";
import Rainfall from "~/views/monitor-control/statistical-analysis/Rainfall";
import MinimumLength from "~/views/monitor-control/statistical-analysis/MinimumLength";

export default {
  name: "StatisticalAnalysis",
  components: { TextTree },
  props: {
    keys: {
      type: String,
      default: "test",
      require: false,
    },
  },
  data() {
    return {
      treeData: null,
      defaultExpandKeys: null,
    };
  },
  created() {
    this.getTreeData().then((res) => {});
  },
  methods: {
    async getTreeData() {
      let temp;
      await Axios({
        url:
          "/leftMenuTree/getLeftMenuTree/" +
          `${sessionStorage.getItem("unitId")}`,
      }).then((res) => {
        console.log(res);
        let list = res.data.parameter.tailingPondList;
        for (let i = 0; i < list.length; i++) {
          for (let key in list[i])
            key === "tailingName"
              ? (list[i].label = list[i][key]) &&
                (list[i].uu = require("../../assets/icon/money.svg"))
              : null;
          list[i].children = list[i].monitorTypeList;
          for (let k = 0; k < list[i].children.length; k++) {
            for (let key in list[i].children[k]) {
              key === "name"
                ? (list[i].children[k].label = list[i].children[k][key])
                : null;
              list[i].children[k].uu = require("../../assets/icon/file.svg");
            }
            list[i].children[k].children = list[i].children[k].monitorPointList;
            for (let j = 0; j < list[i].children[k].children.length; j++) {
              for (let key in list[i].children[k].children[j]) {
                key === "name"
                  ? (list[i].children[k].children[j].label =
                      list[i].children[k].children[j].name)
                  : null;
                switch (list[i].children[k].id) {
                  case 1:
                    list[i].children[k].children[j].component = MinimumLength;
                    list[i].children[k].children[
                      j
                    ].uu = require("../../assets/icon/gt.svg");
                    break;
                  case 2:
                    list[i].children[k].children[j].component = WaterLevel;
                    list[i].children[k].children[
                      j
                    ].uu = require("../../assets/icon/ksw.svg");
                    break;
                  case 3:
                    list[i].children[k].children[
                      j
                    ].component = SurfaceDisplacement;
                    list[i].children[k].children[
                      j
                    ].uu = require("../../assets/icon/bmwy.svg");
                    break;
                  case 4:
                    list[i].children[k].children[
                      j
                    ].component = InteriorDisplacement;
                    list[i].children[k].children[
                      j
                    ].uu = require("../../assets/icon/nbwy.svg");
                    break;
                  case 5:
                    list[i].children[k].children[j].component = SaturationLine;
                    list[i].children[k].children[
                      j
                    ].uu = require("../../assets/icon/jrx.svg");
                    break;
                  case 6:
                    list[i].children[k].children[j].component = Rainfall;
                    list[i].children[k].children[
                      j
                    ].uu = require("../../assets/icon/jsl.svg");
                    break;
                }
              }
            }
          }
        }
        temp = list;
      });
      this.treeData = temp;
      return temp;
    },
    leafClick(d, node, tree) {
      sessionStorage.setItem("index", d.index);
    },
  },
};
</script>
<style scoped>
.content {
  margin-top: 8px;
  display: flex;
}
</style>

<style>
.small-padding-card > .el-card__body {
  padding: 3px 8px;
  width: 100%;
}
</style>
